<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use app\portal\model\PortalCategoryModel;

class SearchController extends HomeBaseController
{
    /**
     * 搜索
     * @return mixed
     */
    public function index()
    {
        $search = $this->request->param();

        $portalCategoryModel = new PortalCategoryModel();
        if (empty($search['keyword'])) {
            $this -> error("关键词不能为空！请重新输入！");
        }
        $category = $portalCategoryModel->CategoryOne($search['id']);

        $keyword = [];
        //是否根据分类查询
        if (isset($search['cid'])) {
           $searcid = $search['cid'];
        }
        $keyword[] = ['post.post_title','like','%'.$search['keyword'].'%'];
        // $keyword['post.post_title'] = array('like','%'.$search['keyword'].'%');
        $this->assign("search", $keyword);
        $this->assign("searcid", $searcid);

        $listTpl = empty($category['list_tpl']) ? 'search' : $category['list_tpl'];

        return $this->fetch('/' . $listTpl);
    }
}
